package com.swz.dcrm.adpter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.TextView;

import com.swz.dcrm.R;
import com.swz.dcrm.base.ViewHolder;
import com.swz.dcrm.model.CarModelTag;

import java.util.List;

public class CarModelTagAdapter extends CustomAdapter<CarModelTag>{
    private int status;
    private boolean edit;
    private int type;
    int tagType;
    public OnAddItemListener onAddItemListener;
    public interface OnAddItemListener{
        void onAdd(CarModelTag carModelTag);
    }
    public CarModelTagAdapter(Context context,  List<CarModelTag> datas,int status,int type) {
        super(context, R.layout.item_car_model_tag, datas);
        this.status=status;
        if(status==1||status==2){
            tagType=1;
        }else {
            tagType=0;
        }
        this.type=type;
    }

    @Override
    protected void convert(ViewHolder holder, CarModelTag carModelTag, int position) {
        TextView t=  holder.getView(R.id.tv);

        carModelTag.setType(type);
        switch (status){
            case 1:

                t.setBackgroundResource(R.drawable.shape_car_model_tag1);
                t.setTextColor(mContext.getResources().getColor(R.color.blue_0f6eff));
                break;
            case 2:

                t.setBackgroundResource(R.drawable.shape_car_model_tag2);
                t.setTextColor(mContext.getResources().getColor(R.color.orange_ff8730));
                break;
            case 3:

                t.setBackgroundResource(R.drawable.shape_car_model_tag3);
                t.setTextColor(mContext.getResources().getColor(R.color.gary_6f777d));
                break;
        }
        if(carModelTag.getTagContext().equals("添加标签")){
            t.setBackgroundResource(R.drawable.shape_car_model_tag4);
            t.setTextColor(Color.parseColor("#00c777"));
            Drawable drawable=mContext.getResources().getDrawable(R.mipmap.add_line);
            drawable.setBounds(0,0,drawable.getMinimumWidth(),drawable.getMinimumHeight());
            t.setCompoundDrawables(drawable, null, null, null);
            t.setOnClickListener(v -> {
                if(onAddItemListener!=null){
                    carModelTag.setType(type);
                    carModelTag.setTagType(tagType);
                    onAddItemListener.onAdd(carModelTag);
                }
            });
        }else {
            t.setOnClickListener(v -> {

            });
            t.setCompoundDrawables(null, null, null, null);
        }
        holder.setOnClickListener(R.id.iv_remove,v -> {
            setCurrentClickPosition(position);
            if(onClickListener!=null){
                onClickListener.onItemClick(carModelTag);
            }
        });
        if(edit&&carModelTag.getId()!=0){
            holder.getView(R.id.iv_remove).setVisibility(View.VISIBLE);
        }else {
            holder.getView(R.id.iv_remove).setVisibility(View.GONE);
        }
        t.setText(carModelTag.getTagContext());
    }
    public void edit(boolean edit){
        this.edit=edit;
        notifyDataSetChanged();
    }

    public void setOnAddItemListener(OnAddItemListener onAddItemListener) {
        this.onAddItemListener = onAddItemListener;
    }
}
